<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body></body>
<script>
    /* 
                          闭包的运用
                      1.隐藏数据
                      2.如做一个缓存的工具
                      */
    function createCache() {
        let data = {}; //闭包中的数据，被隐藏，不被外界访问
        return {
            set(key, value) {
                data[key] = value;
            },
            get(key, value) {
                return data[key];
            },
        };
    }
    let c = createCache();
    c.set("a", 10);
    console.log(c.get("a"));
    c.set("b", 20);
    console.log(c.get("b"));
</script>

</html>